package com.common.redis.notify;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;


@Slf4j
public abstract class AbstractRedisKeyExpirationListener extends KeyExpirationEventMessageListener {


    public AbstractRedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }


    @Override
    public void onMessage(Message message, byte[] pattern) {
        handlerMsg(message);
    }


    /**
     * 调用子类去消费消息
     *
     */
    protected final void handlerMsg(Message message)  {
        String expiredKey = message.toString();
        handler(expiredKey);
    }


    protected abstract void handler(String str);





}
